package com.future.mayi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.model.MessageModel;
import com.future.mayi.view.xrecyclerview.XRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SystemMessageAdapter extends BaseRecyclerViewAdapter<MessageModel> {


    public SystemMessageAdapter(Context context, XRecyclerView recyclerView) {
        super(context, null, recyclerView);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getView(parent, R.layout.layout_message_system_item));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        ViewHolder holder = (ViewHolder) viewHolder;
        if (mOnItemClickListener != null)
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItem(v, position);
                }
            });

        MessageModel model = getItem(position);

        holder.ivIcon.setImageResource(model.getType() == 3 ? R.drawable.img_message_3 : R.drawable.img_message_0);

        setText(holder.tvTime, model.getCreatetime());
        setText(holder.tvTitle, model.getTitle());
        setText(holder.tvContent, model.getSubtitle());

        if (model.getIs_read() == 1) {
            holder.ivRed.setVisibility(View.GONE);
            holder.tvTitle.setTextColor(mContext.getResources().getColor(R.color.sub_text_color));
            holder.tvContent.setTextColor(mContext.getResources().getColor(R.color.sub_text_color));
        } else {
            holder.ivRed.setVisibility(View.VISIBLE);
            holder.tvTitle.setTextColor(mContext.getResources().getColor(R.color.main_text_color));
            holder.tvContent.setTextColor(mContext.getResources().getColor(R.color.main_text_color));
        }


        if (model.getType()==10){
            holder.viewDetails.setVisibility(View.GONE);
            holder.tvDetails.setVisibility(View.GONE);
        }else {
            holder.viewDetails.setVisibility(View.VISIBLE);
            holder.tvDetails.setVisibility(View.VISIBLE);
        }


    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_icon)
        ImageView ivIcon;
        @BindView(R.id.iv_red)
        ImageView ivRed;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_content)
        TextView tvContent;
        @BindView(R.id.tv_details)
        TextView tvDetails;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.view_details)
        View viewDetails;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
